package com.xzx.producer;

import com.xzx.producer.bean.Contact;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2024/8/4 22:06
 */
public class AppProducer {
    public static void main(String[] args) throws IOException {
        if (args.length < 1) {
            System.out.println("请输入正确的参数，格式：java -jar producer.jar outPath");
            System.exit(1);
        }
        String outPath = args[0];

        InputStream resourceAsStream = AppProducer.class.getResourceAsStream("/contact.log");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceAsStream));
        String line;
        List<Contact> contacts = new ArrayList<>();
        while ((line = bufferedReader.readLine()) != null) {
            Contact contact = new Contact();
            String[] split = line.split("\t");
            contact.setPhone(split[0]);
            contact.setName(split[1]);
            contacts.add(contact);
        }
        bufferedReader.close();
        System.out.println(contacts);

        // 开始写数据
        Producer producer = new Producer(contacts, outPath);
        producer.start();
        // 停止写数据
        producer.stop();
    }
}
